<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>用户注册</title>
        <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
        <meta content="yes" name="apple-mobile-web-app-capable"/>
        <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
        <meta content="telephone=no" name="format-detection"/>
        <link href="../css/stylezcy.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="../js/jqueryzcy.js"></script>
        <script type="text/javascript" src="js/time.js"></script>
    </head>

    <body>
      <header  class="ui_button"></header>
        <section class="aui-flexView">
            <header class="aui-navBar aui-navBar-fixed">
                <a onclick="closeWin()" class="aui-navBar-item">
                    <i class="icon icon-return"></i>
                </a>
                <div class="aui-center">
                    <span class="aui-center-title">找回密码</span>
                </div>
                <a href="javascript:;" class="aui-navBar-item">
                    <i class="icon icon-news"></i>
                </a>
            </header>
            
                <div class="aui-code-box">
                    
                        <p class="aui-code-line">
                            <input type="text" class="aui-code-line-input" name="search" value="" id="username" autocomplete="off" placeholder="请输入手机号"/>
                        </p>
                        
                        <p class="aui-code-line aui-code-line-clear">
                            <input id="yzcode" type="text" class="aui-code-line-input" autocomplete="off" placeholder="短信验证码"/>
                            <input id="btn1" type="button" name="button" class="aui-btn-default" value="获取验证码" onclick="getCode()"/>
                            
                        </p>
                        <p class="aui-code-line">
                            <input type="text" class="aui-code-line-input" name="search" value="" id="password" autocomplete="off" placeholder="请输入新密码"/>
                        </p>
                        
                        
                        <div class="aui-code-btn">
                            <button onclick="toReg()">找回密码</button>
                        </div>
                   
                </div>
            
        </section>
        <script type="text/javascript" charset="utf-8">
            $(function() {

                $(".aui-code-line-input").addClear();

            });
        </script>
    </body>
    
    
    
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript">
    var api_url = localStorage.getItem('api_url');
    var onoff = true;
    var code_data = '';
    apiready = function () {
      api.parseTapmode();
      var header = $api.byId('aui-header');
      $api.fixStatusBar(header);
      var headerPos = $api.offset(header);
      var body_h = $api.offset($api.dom('body')).h;

    }
    function closeWin(){
        api.closeWin({
        });
    }


    function toReg(){
      var password = $api.val($api.byId('password'));
      var username = $api.val($api.byId('username'));
      var yzcode = $api.val($api.byId('yzcode'));
      var user_id = localStorage.getItem('user_id');
      var lao_pswd = localStorage.getItem('password');
      if(username == ''){
        api.alert({
            title: '警告！~',
            msg: '请输入登录账号',
        });
        return;
      }
      if(yzcode == ''){
        api.alert({
            title: '警告！~',
            msg: '请输入验证码',
        });
        return;
      }
      if(password == ''){
        api.alert({
            title: '警告！~',
            msg: '请输入密码',
        });
        return;
      }
      if(username.length != 11){
        api.alert({
            title: '警告！~',
            msg: '请输入11位手机号码',
        });
        return;
      }
      if(username.length < 6){
        api.alert({
            title: '警告！~',
            msg: '请输入6位以上密码',
        });
        return;
      }
      if (yzcode != code_data) {
        api.alert({
            title: '糟糕~',
            msg: '短信验证码不正确',
        });
        return;

      }
      api.ajax({
          url: api_url+'/login/login/repasss.html',
          method: 'get',
          data: {
              values: {
                  username:username,
                  password:password,
                  key: yzcode
              }
          }
      },function(ret, err){
          if (ret) {
              if (ret.code == 0) {
                api.alert({
                    title: '修改失败！',
                    msg: ret.msg,
                });
              }else {
                localStorage.setItem('password',password);
                api.alert({
                    title: '修改成功',
                    msg: '请重新登录！',
                });
                api.sendEvent({
                  name: 'outLogin',
                  extra: {
                  }
                });

                api.closeWin();
              }
          } else {
            api.alert({
                title: '糟糕~',
                msg: '网络错误！',
            });
          }
      });
    }


    function openLogin(name,password){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'login',
            url: './login.html',
            pageParam:{name:name,password:password},
        });
    }

    //获取验证码
    function getCode(){
      var yzcode = $api.val($api.byId('yzcode'));
      var username = $api.val($api.byId('username'));
      if (!onoff) {
        return;
      }
      onoff = false;

      if(username == ''){
        api.alert({
            title: '警告！~',
            msg: '请输入手机号码',
        });
        onoff = true;
        return;
      }
      if(username.length != 11){
        api.alert({
            title: '警告！~',
            msg: '请输入11位手机号码',
        });
        onoff = true;
        return;
      }
      code_data = RndNum(6);
      var content = escape('#code#='+code_data);
      //alert(content);
      api.ajax({
          url: api_url+'login/login/yzcode1.html',
          method: 'get',
          data: {
              values: {
                  username: username,
                  key: code_data
              }
          }
      },function(ret, err){
        if (ret.code==0) {
          onoff = true;
          api.alert({
              title: '提示',
              msg: ret.msg,
          });
          return;
        }else {
          onoff = true;
          getApicode(username,code_data,content);
        }
      });

    }
    //生成验证码
    function RndNum(n){
      var rnd="";
      for(var i=0;i<n;i++)
          rnd+=Math.floor(Math.random()*10);
      return rnd;
    }

    function getApicode(username,content,fasong) {
      var btn1 = $api.byId('btn1');
      
      api.ajax({
        url: api_url+'/login/login/fsdx1',
        method: 'get'
      },function(ret, err){
      //  var url = 'http://api.978w.cn/yzmsms/index/appkey/'+ret.appkey+'/phone/'+username+'/moban/'+ret.mbid+'/app/喵喵视界/code/'+code_data;
        //alert( JSON.stringify(url) );
        //return false;
          api.ajax({
              //url: 'http://v.juhe.cn/sms/send?mobile='+username+'&tpl_id=118055&tpl_value='+content+'&key=bf7e3bb0a7768d3d9452183c7148cc17',
              url: 'http://v.juhe.cn/sms/send?mobile='+username+'&tpl_id='+ret.mbid+'&tpl_value='+fasong+'&key='+ret.appkey,
              method: 'get'
          },function(ret, err){
                  api.toast({
                      msg: '发送成功',
                      duration: 1000,
                      location: 'middle'
                  });
                  
          });

      });

    }

    function openWin(name){
          var delay = 0;
          if(api.systemType != 'ios'){
              delay = 300;
          }
          api.openWin({
              name: ''+name+'',
              url: ''+name+'.html',
              bounces:false,
              delay: delay,
              slidBackEnabled:true,
              vScrollBarEnabled:false
          });
      }
</script>
</html>
